import { http } from 'msw';
import { JsonResult } from '../helper';

const baseURL = import.meta.env.VITE_APP_BASE_API;

export default [
  // 登录
  http.post(baseURL + '/login', async ({ request }) => {
    // 解构查询参数
    const res: any = await request.json();
    const { account, password } = res;
    if (account === 'admin' && password === 'password') {
      return JsonResult.sucess({
        token: 'abc2025',
      });
    } else {
      return JsonResult.error('账号或密错误');
    }
  }),
  http.get(baseURL + '/menus', ({ request }) => {
    const { searchParams } = new URL(request.url);
    const userId = searchParams.get('userId');
    return JsonResult.sucess([
      {
        path: '/list',
        title: '列表页',
        icon: 'Tickets',
        children: [
          {
            path: '/list/basic',
            title: '基础列表',
          },
          {
            path: '/list/table',
            title: '表格列表',
          },
        ],
      },
      {
        path: '/system',
        title: '系统管理',
        icon: 'Setting',
        children: [
          {
            path: '/system/account',
            title: '账号管理',
          },
          {
            path: '/system/role',
            title: '角色管理',
          },
          {
            path: '/system/menu',
            title: '菜单管理',
          },
        ],
      },
    ]);
  }),
];
